/*
 * Created on 12 juin 08 by Joseph Poidevin (poidevin@gmail.com)
 */
package org.bigcrunch.processing.libcv;

import processing.core.PImage;
import toxi.video.capture.SimpleCapture;
import JMyron.JMyron;

public class JMyronCapture extends JMyron implements SimpleCapture{
    
    protected String error;
    protected PImage frame;
    
    public JMyronCapture(){
        super();
    }
    
    public String getError() {
        return error;
    }

    public PImage getFrame() {
        update();
        frame.pixels = image();
        //frame.updatePixels();
        return frame;
    }

    public int getHeight() {
        return frame.height;
    }

    public int getWidth() {
        return frame.width;
    }

    public boolean initVideo(String deviceID, int width, int height, int fps) {
        try {
            frame = new PImage(width,height);
            frame.format = PImage.RGB;
            start(width, height);
        }catch(Exception e){
            e.printStackTrace();
            error = e.getMessage();
            return false;
        }
        return true;
    }

    public void shutdown() {
        stop();
    }
}
